
// <copyright file="CustomPerfCounters.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The custom perf counters.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Diagnostics.Performance
{
    using System.Collections.Generic;

    /// <summary>
    /// The custom perf counters.
    /// </summary>
    public sealed class CustomPerfCounters : AbstractDisposable
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the category name.
        /// </summary>
        public string CategoryName { get; set; }

        /// <summary>
        /// Gets or sets the counters.
        /// </summary>
        public List<CustomCounterInfo> Counters { get; set; }

        /// <summary>
        /// Gets a value indicating whether is started.
        /// </summary>
        public bool IsStarted { get; private set; }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The start.
        /// </summary>
        public void Start()
        {
            if (!this.IsStarted)
            {
                this.IsStarted = true;
                PerfCounterManager.Instance.AddCustomPerfCounters(this);
            }
        }

        /// <summary>
        /// The stop.
        /// </summary>
        public void Stop()
        {
            if (this.IsStarted)
            {
                this.IsStarted = false;
                PerfCounterManager.Instance.RemoveCustomPerfCounters(this.CategoryName);
            }
        }

        #endregion Public Methods and Operators

        #region Methods

        /// <summary>
        /// The dispose.
        /// </summary>
        /// <param name="disposing">
        /// The disposing.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            this.Stop();
        }

        #endregion Methods
    }
}
